import { Form, Input, Modal } from "antd"

const LinkModal = ({ isModalOpen, setIsModalOpen, getLinkValues }: { isModalOpen: boolean, setIsModalOpen: Function, getLinkValues: Function }) => {
    const [form] = Form.useForm();
    const onOk = async () => {
        try {
            const { text, url }: any = await form.validateFields();
            getLinkValues({ text, url })
            setIsModalOpen(false);
            form.resetFields();
        } catch (error) {
            console.log(error)
        }
    };
    const oncancel = () => {
        form.resetFields();
        setIsModalOpen(false);
    }
    return <Modal okText="确定" cancelText="取消" title="设置超链接" open={isModalOpen} onOk={onOk} onCancel={oncancel}>
        {/* editor.commands.insertContent */}
        <Form form={form} labelCol={{ span: 3 }}
            wrapperCol={{ span: 20 }}>
            <Form.Item name='text' label="文本" rules={[{ required: true, message: '文本不能为空！' }]}>
                <Input />
            </Form.Item>
            <Form.Item name='url' label="链接" rules={[{ required: true, message: '链接不能为空！' }, { type: 'url', warningOnly: true, message: '请输入正确链接！' },]}>
                <Input />
            </Form.Item>
        </Form>
    </Modal>
}

export default LinkModal